/*
Copyright 2005-2015 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.swing.dings.tester;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import com.fricano.java42.swing.dings.J42SwingDingController_SlideWindow.Alignment;
import com.fricano.java42.swing.dings.J42SwingDingManager_SlideWindow;
import com.fricano.java42.swing.dings.J42SwingDing_Factory;
import com.fricano.java42.swing.dings.components.J42JWindow_Manageable;

final public class J42SwingDing_SlidableTest_04 {

    final static JButton              jButton    = new JButton("Slide");
    final static J42JWindow_Manageable jFrameBad  = new J42JWindow_Manageable();
    final static JFrame               jFrameGood = new JFrame();
    final static JButton              slider     = new JButton("SimpleSlideTest");
    static J42SwingDing_Factory       factory    = null;
    static J42SwingDingManager_SlideWindow manager    = null;

    static public void main(final String[] args) throws Exception {

        // not the glass pane
        final JFrame jFrame = jFrameBad;

        // the bug
        jFrameBad.getManager().setTransparancy(33);

        factory = new J42SwingDing_Factory(jFrame);

        jFrame.setUndecorated(true);

        manager = factory.create_SlideManager();
        slider.setSize(150, 180);

        jFrame.setLayout(new FlowLayout());

        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent actionEvent) {
                if (manager.isClosed()) {
                    manager.slideOpen(true);
                }
                else {
                    manager.slideClosed(true);
                }
            }
        });

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                jFrame.add(jButton);
                jFrame.setSize(200, 200);
                jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                jFrame.setLocationRelativeTo(null);
                jFrame.setVisible(true);
            }
        });

        manager.attachSlider(Alignment.EXTERIOR_RIGHT, slider, 42, 500, 0, 0);
    }
}
